package com.lty.jeeg.server.modules.tms.service.impl;

import com.lty.jeeg.server.common.page.table.PageTableHandler;
import com.lty.jeeg.server.common.page.table.PageTableRequest;
import com.lty.jeeg.server.common.page.table.PageTableResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lty.jeeg.server.modules.tms.dao.TaskAtUsersDao;
import com.lty.jeeg.server.modules.tms.model.TaskAtUsers;
import com.lty.jeeg.server.modules.tms.service.TaskAtUsersService;

/**
 * @author : LTY
 * @date : 2019-04-09 14:34:25
 * Description : 任务At用户表
 */
@Service
@Slf4j
public class TaskAtUsersServiceImpl implements TaskAtUsersService {

    private final TaskAtUsersDao taskAtUsersDao;

    @Autowired
    public TaskAtUsersServiceImpl(TaskAtUsersDao taskAtUsersDao) {
        this.taskAtUsersDao = taskAtUsersDao;
    }

    @Override
    public TaskAtUsers getById(Long id) {
        return taskAtUsersDao.getById(id);
    }

    @Override
	@Transactional(rollbackFor = Exception.class)
	public int delete(Long id) {
		log.debug("删除TaskAtUsers=>{}", id);
		return taskAtUsersDao.delete(id);
	}

    @Override
	@Transactional(rollbackFor = Exception.class)
	public int update(TaskAtUsers taskAtUsers) {
	    taskAtUsers.preUpdate();
        log.debug("修改TaskAtUsers=>{}", taskAtUsers.getId());
        return taskAtUsersDao.update(taskAtUsers);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long save(TaskAtUsers taskAtUsers) {
        taskAtUsers.preInsert();
        taskAtUsersDao.save(taskAtUsers);
        log.debug("新增TaskAtUsers=>{}", taskAtUsers.getId());
        return taskAtUsers.getId();
    }

    @Override
    public PageTableResponse list(PageTableRequest request) {
        return new PageTableHandler(
                request1 -> taskAtUsersDao.count(request1.getParams()),
                request2 -> taskAtUsersDao.list(
                        request2.getParams(), request2.getOffset(), request2.getLimit()))
                .handle(request);
    }

    @Override
    public int deleteByTaskIdAndMattersId(Long taskId, Long mattersId) {
        return taskAtUsersDao.deleteByTaskIdAndMattersId(taskId, mattersId);
    }


}
